package com.gxa.modules.pc.fee.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.common.utils.PageUtils;
import com.gxa.common.utils.Result;
import com.gxa.modules.model.entity.fee.OutpatientConsumptionRecords;
import com.gxa.modules.pc.fee.dto.*;
import com.gxa.modules.pc.fee.mapper.OutpatientConsumptionRecordsMapper;
import com.gxa.modules.pc.fee.service.OutpatientConsumptionRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 门诊消费记录表 服务实现类
 * </p>
 *
 * @author gxa
 * @since 2022-11-12 05:31:54
 */
@Service
public class OutpatientConsumptionRecordsServiceImpl extends ServiceImpl<OutpatientConsumptionRecordsMapper, OutpatientConsumptionRecords> implements OutpatientConsumptionRecordsService {

    @Autowired
    private OutpatientConsumptionRecordsMapper ocrm;
    @Override
    public Result queryAll(@RequestBody OutPatientSearchDto outPatientSearchDto) {
        Integer pageNum1 = outPatientSearchDto.getPageNum();
        Integer pageSize = outPatientSearchDto.getPageSize();
        Integer pageNum2 = (pageNum1-1)*pageSize;
        outPatientSearchDto.setPageNum(pageNum2);
        List<OutPatientCoRecordsdto> outPatientCoRecordsdtos = ocrm.queryAll(outPatientSearchDto);
        Integer count = ocrm.count(outPatientSearchDto);
        PageUtils pageUtils = new PageUtils(outPatientCoRecordsdtos, count, pageSize, pageNum1);
        return new Result().ok(pageUtils);
    }

    @Override
    public Map<String, Object> queryByOrderId(String orderId) {
        HashMap<String, Object> map = new HashMap<>();
        List<PatientPcdto> patientPcdtos = ocrm.queryById(orderId);
        List<OrderDetialPcdto> orderDetialPcdtos = ocrm.queryByOrdersId(orderId);
//        List<OutPatientDatePcdto> outPatientDatePcdtos = ocrm.queryOutPatientByOrderId(orderId);
        List<OutPatientDatePcdto> outPatientDatePcdtos = ocrm.queryOutPatientDetailByOrderId(orderId);
        map.put("patient", patientPcdtos);
        map.put("outPatient", outPatientDatePcdtos);
        map.put("orderDetail", orderDetialPcdtos);
        return map;
    }

    @Override
    public void updateRemarks(String orderId, String orderNotes) {
        ocrm.updateRemarks(orderId, orderNotes);
    }
}
